import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

/// 环境信息组件
class EnvironmentInfo extends StatelessWidget {
  const EnvironmentInfo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withOpacity(0.1),
            spreadRadius: 1,
            blurRadius: 5,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(children: [
            // 跳转按钮
            ElevatedButton(
              onPressed: () => context.go('/opacity'),
              child: const Text('透明度控制演示'),
            ),
            // 跳转按钮
            ElevatedButton(
              onPressed: () => context.go('/deviceHome'),
              child: const Text('拖拽排序演示'),
            ),
            // 红外解析页面跳转按钮
            ElevatedButton(
              onPressed: () => context.go('/infrared'),
              child: const Text('红外解析演示'),
            ),
          ]),
          // 位置信息
          Row(
            children: [
              Text(
                '呼和浩特市 和林格尔县',
                style: TextStyle(fontSize: 16, color: Colors.grey[700]),
              ),
              const Spacer(),
              Row(
                children: [
                  Icon(Icons.eco, color: Colors.green[300], size: 18),
                  const SizedBox(width: 4),
                  Text(
                    '室内空气清洁指数 85',
                    style: TextStyle(fontSize: 14, color: Colors.green[300]),
                  ),
                  Icon(Icons.chevron_right, color: Colors.green[300], size: 18),
                ],
              ),
            ],
          ),
          const SizedBox(height: 12),
          // 减碳信息
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
            decoration: BoxDecoration(
              color: Colors.amber[50],
              borderRadius: BorderRadius.circular(20),
            ),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(
                  '本月减碳总量 0.23',
                  style: TextStyle(fontSize: 14, color: Colors.amber[700]),
                ),
                Icon(Icons.chevron_right, color: Colors.amber[700], size: 18),
              ],
            ),
          ),
          const SizedBox(height: 16),
          // 环境数据
          Row(
            children: [
              _buildEnvironmentDataItem(Icons.thermostat, '37°C'),
              const SizedBox(width: 24),
              _buildEnvironmentDataItem(Icons.water_drop, '50%'),
              const SizedBox(width: 24),
              _buildEnvironmentDataItem(null, 'PM2.5 120'),
            ],
          ),
          const SizedBox(height: 12),
          // 更新时间
          Row(
            children: [
              Text(
                '更新于: 2020/8/10 12:00',
                style: TextStyle(fontSize: 12, color: Colors.grey[500]),
              ),
              const Spacer(),
              // 键关机按钮
              Container(
                padding:
                    const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
                decoration: BoxDecoration(
                  color: Colors.blue[300],
                  borderRadius: BorderRadius.circular(20),
                ),
                child: const Text(
                  '键关机',
                  style: TextStyle(color: Colors.white, fontSize: 14),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  /// 构建环境数据项
  Widget _buildEnvironmentDataItem(IconData? icon, String text) {
    return Row(
      children: [
        if (icon != null) ...[
          Icon(icon, color: Colors.grey[400], size: 20),
          const SizedBox(width: 4),
        ],
        Text(
          text,
          style: TextStyle(fontSize: 16, color: Colors.grey[600]),
        ),
      ],
    );
  }
}
